package cn.wit.test;

import java.util.Arrays;

/**
 * 冒泡排序
 * 
 * @author 16604
 *
 */
public class DemoBubbleSort {
	public static void main(String[] args) {
		int[] a = { 2, 1, 34, 5 };

		System.out.println("未排序得数组" + Arrays.toString(a));

		bubbleSort(a);

		System.out.println("排序得数组" + Arrays.toString(a));

	}

	// 冒泡排序
	public static void bubbleSort(int[] nums) {

		for (int i = 0; i < nums.length; i++) {
			for (int j = nums.length - 2; j >= i; j--) {
				if (nums[j] > nums[j + 1]) {
					int temp;
					temp = nums[j];
					nums[j] = nums[j + 1];
					nums[j + 1] = temp;
				}
			}
		}
	}

}
